# ----- 猫眼票房 ----     base64 加密  md5加盐 随机数  时间戳
import base64
import hashlib
import math
import random
import time

import requests


def getData():
    url = 'https://piaofang.maoyan.com/dashboard-ajax/movie'
    useragents = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.183'
    headers = {
        'User-Agent':useragents,
        'Referer':'https://piaofang.maoyan.com/dashboard/movie'
    }

    useragents = str(base64.b64encode(useragents.encode('utf-8')),'utf-8')
    index = str(round(random.random() * 1000))
    times = str(math.ceil(time.time() * 1000))
    # "method=GET&timeStamp={}&User-Agent={}&index={}&channelId=40009&sVersion=2&key=A013F70DB97834C0A5492378BD76C53A"
    content = "method=GET&timeStamp={}&User-Agent={}&index={}&channelId=40009&sVersion=2&key=A013F70DB97834C0A5492378BD76C53A".format(times,useragents,index)
    md5 = hashlib.md5()
    md5.update(content.encode('utf-8'))
    sign = md5.hexdigest()

    params = {
        'orderType': '0',
        'uuid': '17d79b87a00c8-015087c7514df4-5919145b-144000-17d79b87a00c8',
        # 时间戳
        'timeStamp': times,
        # base64加密
        'User-Agent': useragents,
        # 随机数 * 1000取整
        'index': index,
        'channelId': '40009',
        'sVersion': '2',
        # md5加密
        'signKey': sign
    }

    resps = requests.get(url = url , headers = headers, params = params).content.decode()
    print(resps)

if __name__ == '__main__':
    getData()



